// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		sign: [{
				"className": "语文二班",
				"count": 15,
				"sign": 10,
				"path": '/static/打卡.png',
				"create_time": "2019-09-15 22:58:48"
			},
			{
				"className": "测试班",
				"count": 50,
				"sign": 22,
				"path": '/static/打卡.png',
				"create_time": "1978-07-07 22:51:14"
			},
			{
				"className": "区该到构方位",
				"count": 50,
				"sign": 22,
				"path": '/static/打卡.png',
				"create_time": "1974-12-25 15:08:35"
			},
			{
				"className": "经表光间军",
				"count": 50,
				"sign": 40,
				"path": '/static/打卡.png',
				"create_time": "1977-12-02 09:54:29"
			},
			{
				"className": "行就完己",
				"count": 50,
				"sign": 40,
				"path": '/static/打卡.png',
				"create_time": "1985-11-28 15:31:11"
			},
			{
				"className": "名群即较容",
				"count": 50,
				"sign": 40,
				"path": '/static/打卡.png',
				"create_time": "1970-06-19 13:21:35"
			}
		],
		signDetail: [{
				"id": 27,
				"cname": "毛秀英",
				"state": 0
			},
			{
				"id": 4,
				"cname": "贾涛",
				"state": 1
			},
			{
				"id": 34,
				"cname": "姜娜",
				"state": 1
			},
			{
				"id": 82,
				"cname": "胡磊",
				"state": 0
			},
			{
				"id": 18,
				"cname": "冯霞",
				"state": 1
			},
			{
				"id": 28,
				"cname": "陆艳",
				"state": 1
			},
			{
				"id": 77,
				"cname": "黎明",
				"state": 0
			},
			{
				"id": 29,
				"cname": "郑丽",
				"state": 1
			},
			{
				"id": 88,
				"cname": "田强",
				"state": 0
			},
			{
				"id": 51,
				"cname": "夏丽",
				"state": 1
			},
			{
				"id": 20,
				"cname": "张桂英",
				"state": 1
			},
			{
				"id": 68,
				"cname": "林敏",
				"state": 1
			},
			{
				"id": 37,
				"cname": "汤洋",
				"state": 0
			},
			{
				"id": 53,
				"cname": "谢艳",
				"state": 1
			},
			{
				"id": 21,
				"cname": "罗伟",
				"state": 1
			}
		]
	},
	mutations: {
		changeList(state, payload) {
			let date = new Date();
			let createTime = date.getFullYear() + '-' + Number(date.getMonth() + 1) + '-' + date.getDate() +
				' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
			state.sign.unshift({
				"className": payload,
				"count": 49,
				"sign": 30,
				"path": '/static/打卡.png',
				"create_time": createTime
			})
		},
		change(state, payload) {
			console.log(payload);
			let arr = state.signDetail.map(value => {
				if (value.id === payload) {
					value.state === 0 ? value.state = 1 : value.state = 0;
					return value
				} else {
					return value;
				}
			});
			state.signDetail = [...arr];
		}
	},
	getters: {
		completed(state) {
			return state.signDetail.filter(value => value.state === 1)
		},
		uncompleted(state) {
			return state.signDetail.filter(value => value.state === 0)
		}
	}
})
export default store
